package com.zzb.weixin.model;

import com.zzb.weixin.constant.WXJsonName;
import com.zzb.weixin.json.JsonObject;

public class AccessToken {
	private String accessToken;//获取到的凭证
	private int expiresIn;//凭证有效时间，单位：秒
	private long createdTime;//凭证创建时间
	private long expiresTime;//凭证超时时间
	public AccessToken() {
	}
	public AccessToken(JsonObject jo) {
		this.setAccessToken(jo.getAsString(WXJsonName.ACCESS_TOKEN));
		this.setExpiresIn(jo.getAsInt(WXJsonName.EXPIRES_IN));
		this.setCreatedTime(System.currentTimeMillis()-10000);
		this.setExpiresTime(this.getCreatedTime() + this.getExpiresIn()*250);
	}
	/**
	 * 当前accessToken是否到期
	 * @return
	 */
	public boolean isExpires(){
		return System.currentTimeMillis() >= this.getExpiresTime();
	}
	/**
	 * 获取剩余有效期 
	 * @return
	 */
	public long getExpiresLong(){
		return this.getExpiresTime() - System.currentTimeMillis();
	}
	public String getAccessToken() {
		return accessToken;
	}
	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}
	public int getExpiresIn() {
		return expiresIn;
	}
	public void setExpiresIn(int expiresIn) {
		this.expiresIn = expiresIn;
	}
	public Long getCreatedTime() {
		return createdTime;
	}
	public void setCreatedTime(Long createdTime) {
		this.createdTime = createdTime;
	}
	public long getExpiresTime() {
		return expiresTime;
	}
	public void setExpiresTime(long expiresTime) {
		this.expiresTime = expiresTime;
	}
}
